﻿/**
 * 
 */
package views;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import models.EventData;

import controllers.AddListener;
import controllers.AutorListener;
import controllers.ChengeListener;
import controllers.CloseListener;
import controllers.HelpListener;
import controllers.LoadListener;
import controllers.SaveListener;

/**
 * @author LAP
 *
 */
public class MainFrame extends JFrame {
	private JMenu file;
	
	private JMenu help;
	
	private MainFrameContentCeeper contentCeeper;
	/**
	 * 
	 */
	private static final long serialVersionUID = 3673053262268380722L;
	
	private void createMenu(){
		setJMenuBar(new JMenuBar());
		setFileMenu();
		setHelpMenu();
		setMinimumSize(new Dimension(500, 300));
		pack();
		setVisible(true);
	}
	
	private void setFileMenu(){
		file = new JMenu("Файл");
		file.add(new JMenuItem("Добавить")).addActionListener(new AddListener());
		file.add(new JMenuItem("Изменить")).addActionListener(new ChengeListener());
		file.addSeparator();
		file.add(new JMenuItem("Загрузить")).addActionListener(new LoadListener());
		file.add(new JMenuItem("Сохранить")).addActionListener(new SaveListener());
		file.addSeparator();
		file.add(new JMenuItem("Выход")).addActionListener(new CloseListener());
		getJMenuBar().add(file);
	}
	
	private void setHelpMenu(){
		help = new JMenu("Помощь");
		help.add(new JMenuItem("Справка")).addActionListener(new HelpListener());
		help.add(new JMenuItem("Автор")).addActionListener(new AutorListener());
		getJMenuBar().add(help);
	}
	
	private void createContent(){
		getContentPane().setLayout(new BorderLayout());
		contentCeeper = new MainFrameContentCeeper();
		getContentPane().add(contentCeeper, BorderLayout.CENTER);
	}
	
	private void createGUI(){
		createContent();
		createMenu();
	}
	
	public MainFrame(String title){
		super(title);
		createGUI();
	}
	
	public void addEvent(EventData event) {
		contentCeeper.addEvent(event);
	}
}
